package com.campus.controller;

import com.campus.common.ResponseResult;
import com.campus.model.Student;
import com.campus.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 学员控制器类，用于处理学员相关的HTTP请求
 * @author: hjm
 * @date: 2024/11/22
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 新增学员
     *
     * @param student 学员对象
     * @return 创建结果
     */
    @PostMapping("/create")
    public ResponseResult<String> createStudent(@RequestBody Student student) {
        int result = studentService.createStudent(student);
        return result > 0 ? ResponseResult.ok("学员创建成功") : ResponseResult.error(HttpStatus.INTERNAL_SERVER_ERROR, "学员创建失败");
    }

    /**
     * 批量导入学员
     *
     * @param students 学员对象列表
     * @return 创建结果
     */
    @PostMapping("/create/batch")
    public ResponseResult<String> batchCreateStudents(@RequestBody List<Student> students) {
        int result = studentService.batchCreateStudents(students);
        return result > 0 ? ResponseResult.ok("学员批量创建成功") : ResponseResult.error(HttpStatus.INTERNAL_SERVER_ERROR, "学员批量创建失败");
    }

    /**
     * 审核学员
     *
     * @param id 学员ID
     * @return 审核结果
     */
    @PutMapping("/approve/{id}")
    public ResponseResult<String> approveStudent(@PathVariable int id) {
        int result = studentService.approveStudent(id);
        return result > 0 ? ResponseResult.ok("学员审核成功") : ResponseResult.error(HttpStatus.INTERNAL_SERVER_ERROR, "学员审核失败");
    }

    /**
     * 批量审核学员
     *
     * @param studentIds 学员ID列表
     * @return 审核结果
     */
    @PutMapping("/approve/batch")
    public ResponseResult<String> batchApproveStudents(@RequestBody List<Integer> studentIds) {
        int result = studentService.batchApproveStudents(studentIds);
        return result > 0 ? ResponseResult.ok("学员批量审核成功") : ResponseResult.error(HttpStatus.INTERNAL_SERVER_ERROR, "学员批量审核失败");
    }
}